<?php

class cntrlupload implements viewController {
	private $area;
	private $side;
	private $dependencies = array( );
	private $pageName = "PicBoard Upload";
	private $userObj;
	private $tools = "";

	public function __construct(user &$userObj){
		$this->userObj = $userObj;
		if($this->userObj->getAccessLevel() == -1 || $this->userObj->getAccessLevel() == ""){
			// User is not logged in
			
			header("Location: home");
		} else {
			
			if($_POST['uploadType'] == "uploadImage") {
			
				if($_POST['groupID'] == ""){
					$this->uploadImage();
				} else {
					$this->uploadGroupImage($_POST['groupID']);
				}
			}
		}
	}

	private function uploadImage(){
		if(images::storeImage($this->userObj)){
			if($_POST['redirectTo'] == "") {
				header("Location: home?d=4");
			} else {
				header("Location: " . $_POST['redirectTo']);
			}
		} else {
			header("Location: error?e=5");
		}
	}
	
	private function uploadGroupImage($gID){
		if(images::storeGroupImage($this->userObj, $_POST['groupID'])){
			header("Location: group?id=" . $gID);
		} else {
			header("Location: error?e=5");
		}
	}

	public function getSide(){
		return $this->side;
	}
	
	public function getArea(){
		return $this->area;
	}
	
	public function getDependencies(){
		return $this->dependencies;
	}

	public function getPageName(){
		return $this->pageName;
	}
	
	public function getTools(){
		return $this->tools;
	}

}

?>